package com.yk.airline.dao.city.impl;

import com.yk.airline.dao.city.api.ICityDao;
import com.yk.airline.dao.common.impl.CommonDaoImpl;
import com.yk.airline.model.CityModel;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project Name:airlinecrawler
 * File Name:CityDaoImpl
 * Package Name:com.yk.airline.dao.citydao.impl
 * Date:2018/1/31 11:26
 * Author:dengtianjia
 * Description:
 * Copyright (c) 2018, 重庆云凯科技有限公司 All Rights Reserved.
 */
@Repository("cityDao")
public class CityDaoImpl extends CommonDaoImpl<CityModel> implements ICityDao {

    @Override
    public List<CityModel> findAll() {
        String hql = "from CityModel";
        return super.comSearchDao.findByParams(hql,null);
    }

    @Override
    public int findTotalCount() {
        String hql = "SELECT COUNT(CityModel.id) FROM CityModel";
        return super.comSearchDao.findCount(hql,null);
    }

    /**
     * 根据城市名称查询简称
     * @param name
     * @return
     */
    @Override
    public CityModel findAbbreviateByName(String name){
        Map<String,Object> params=new HashMap<>();
        params.put("name",name);
        String hql = "from CityModel where name =:name";
        return (CityModel) super.comSearchDao.findUnique(hql,params);
    }
}
